/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package HelperClasses.PopulateListAndComboBoxes;


import HelperClasses.PopulateListAndComboBoxes.ComplexItem.cBoxItem;
import entertainmentguide.entity.Area;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import manageDataBase.DBManager;

/**
 *
 * 
 */
public class CreateAreaComboBoxModel {
    // Δημιουργώ την λίστα με τις περιοχές εστιατορίων
    static public ComboBoxModel getModel(){
        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
        ArrayList<Area> Areas = null;
        try {
            // διαβάζω όλες τις περιοχές από την βάση δεδομένων
            DBManager db = new DBManager();
            Areas = db.getAllAreas();
            db.closeDB();
            //εισάγω στην DefaultComboBoxModel τις περιοχές εστιατορίων
            for (Iterator<Area> it = Areas.iterator(); it.hasNext();) {
                Area ar = it.next();
                dcbm.addElement(new cBoxItem(ar.getAreaName(), ar.getAreaId()));
            }
        return dcbm;
        } catch (SQLException ex) {
            Logger.getLogger(CreateAreaComboBoxModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return dcbm;
        }
}
    

